package zhihuilan.controlle.wechatMini;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringEscapeUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zhihuilan.common.WxMiniResponse;
import zhihuilan.common.enums.ResultEnum;
import zhihuilan.common.utils.BaiduMapUtils;
import zhihuilan.common.utils.MD5EncryptionUtils;
import zhihuilan.common.utils.ToolsUtils;
import zhihuilan.config.StaticFiledConfig;
import zhihuilan.controlle.BasicController;
import zhihuilan.dto.*;
import zhihuilan.entity.*;
import zhihuilan.entity.tools.ToolsLocation;
import zhihuilan.entity.tools.baidu.BaiduAddressComponent;
import zhihuilan.entity.tools.baidu.BaiduReverseGeocoding;
import zhihuilan.mapper.MyFactoryProductMapper;
import zhihuilan.params.*;
import zhihuilan.params.query.*;
import zhihuilan.params.save.*;
import zhihuilan.service.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 小程序端API </p>
 * 接口说明：</p>
 *
 * @Module 系统基础用户接口模块
 * @Author chenk
 * @Version 1.0.1 (2025-02-24)
 */
@Slf4j
@RestController
@RequestMapping("/app/Shop")
public class MyShopController extends BasicController {
    @Resource
    private StaticFiledConfig staticFiledConfig;

    @Resource
    private MyShopService myShopService;

    @Resource
    private MyFactoryFavService myFactoryFavService;

    @Resource
    private MyContentBannerService myContentBannerService;

    @Resource
    private MyCategoryShopService myCategoryShopService;

    @Resource
    private MyShopMemberService myShopMemberService;

    @Resource
    private MyShopAlbumCateService myShopAlbumCateService;

    @Resource
    private MyShopAlbumListService myShopAlbumListService;

    @Resource
    private MyCategoryProductService myCategoryProductService;

    @Resource
    private MyCategoryUnitService myCategoryUnitService;

    @Resource
    private MyFactoryProductService myFactoryProductService;

    @Resource
    private MyShopHonorCateService myShopHonorCateService;

    @Resource
    private MyShopHonorService myShopHonorService;

    @Resource
    private MyCartService myCartService;
    @Resource
    private MyOrderService myOrderService;
    @Resource
    private MyOrderDetailService myOrderDetailService;

    /**
     * shoplist_获取工厂列表
     *
     * @param param 通用参数查询类【StaticParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/shoplist")
    public WxMiniResponse shoplist(@RequestBody MyShopQueryParam param) {
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登陆信息，并且返回未登陆的枚举编码；
//            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        Page<MyShop> page = this.myShopService.selectPageList(param);
        WxMiniPageDto<MyShopDto> result = new WxMiniPageDto<>(page.getCurrent(), page.getSize());
        BeanUtils.copyProperties(page, result);
        List<MyShopDto> convertList = page.getRecords().stream().map(po -> {
            MyShopDto shopDto = new MyShopDto();
            BeanUtils.copyProperties(po, shopDto);
            if (!ObjectUtils.isEmpty(shopDto.getPcd())) {
                String[] pcd = shopDto.getPcd().split(",");
                if (pcd.length >= 2) {
                    shopDto.setPcdname(pcd[0] + "-" + pcd[1]);
                } else if (pcd.length == 1) {
                    shopDto.setPcdname(pcd[0]);
                }
            }
            if (!ObjectUtils.isEmpty(currentStaff) && !ObjectUtils.isEmpty(currentStaff.getId())) {
                // 自己是否已关注
                MyFactoryFavQueryParam myFactoryFavQueryParam = new MyFactoryFavQueryParam();
                myFactoryFavQueryParam.setShopid(po.getId());
                myFactoryFavQueryParam.setStaffId(currentStaff.getId());
                Long favCount = this.myFactoryFavService.selectCount(myFactoryFavQueryParam);
                if (ObjectUtils.isEmpty(favCount) || favCount == 0L) {
                    shopDto.setIsfav(0);
                } else {
                    shopDto.setIsfav(1);
                }
            } else {
                shopDto.setIsfav(0);
            }
            return shopDto;
        }).collect(Collectors.toList());
        result.setData(convertList);

//        if (!ObjectUtils.isEmpty(param.getPage()) && param.getPage() <= 1) {
        //加载第一页，或者首次加载，或者切换省市区的时候，为了避免资源重复加载浪费时间，这里控制查询数据，减少重复数据查询；
        MyContentBannerQueryParam queryParam = new MyContentBannerQueryParam();
        if (!ObjectUtils.isEmpty(param.getDistrictid())) {
            //按省份查询广告banner
            queryParam.setDistrictid(param.getDistrictid());
        }
        List<MyContentBanner> banbers = this.myContentBannerService.selectList(queryParam);
        Map<String, Object> map = new HashMap<>();
        map.put("banner", banbers);
        map.put("list", result);
//        }
        return WxMiniResponse.ok(map);
    }

    /**
     * shopcategory1_获取工厂电缆分类
     *
     * @param param 通用参数查询类【StaticParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/shopcategory1")
    public WxMiniResponse shopcategory(@RequestBody StaticParam param) {
        if (ObjectUtils.isEmpty(param)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "接口访问参数异常");
        }
        if (!ObjectUtils.isEmpty(param.getStaffId()) && param.getStaffId() > 0) {
            if (!this.isCheckLogin(param.getGuid())) {
                //如果用户未登陆，提示用户未登陆信息，并且返回未登陆的枚举编码；
                return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
            }
        }
        List<MyCategoryShop> result = myCategoryShopService.selectList(null, null, param.getStaffId(), null);
        return WxMiniResponse.ok(result);
    }

    /**
     * delshopcategory_删除工厂电缆分类
     *
     * @param param 通用参数查询类【StaticParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/delshopcategory")
    public WxMiniResponse delshopcategory(@RequestBody StaticParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(param.getId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "参数id为空");
        }

        MyShop shop = this.myShopService.selectOne(currentStaff.getId(), 1, 1);
        if (!ObjectUtils.isEmpty(shop)) {
            MyCategoryShop categoryShop = myCategoryShopService.selectById(param.getId());
            if (!ObjectUtils.isEmpty(categoryShop)) {
                if (shop.getPid().contains(categoryShop.getCid() + "")) {
                    return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请先退出该分类，再进行删除！");
                }
            }
        }
        // 删除我的工厂电缆分类
        Boolean result = this.myCategoryShopService.deletetById(param.getId(), currentStaff.getId());
        if (result) {
            return WxMiniResponse.ok();
        } else {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "删除失败");
        }
    }

    /**
     * addshopcategory_新增工厂电缆分类
     *
     * @param param 通用参数查询类【StaticParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/addshopcategory")
    public WxMiniResponse addshopcategory(@RequestBody MyCategoryShopSaveParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(param.getName())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "参数：名称为空");
        }
        Boolean isCreated = this.myCategoryShopService.isCreated(1, param.getName(), currentStaff.getId());
        if (isCreated) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "已存在");
        }
        MyCategoryShop entity = this.myCategoryShopService.selectOne(param.getName(), 1);
        MyCategoryShop result = new MyCategoryShop();
        BeanUtils.copyProperties(param, result);
        if (!ObjectUtils.isEmpty(entity)) {
            result.setCid(entity.getId());
        } else {
            result.setStatus(1);
            result.setIsdelete(0);
            result.setFchild(0);
            result.setIsresume(0);
        }
        result.setStaffid(currentStaff.getId());
        result = this.myCategoryShopService.addEntity(result);
        if (!ObjectUtils.isEmpty(result))
            return WxMiniResponse.ok(result);
        else
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "新增失败！");
    }

    /**
     * shopInfo_获取厂家信息
     *
     * @param param 通用参数查询类【StaticParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/shopInfo")
    public WxMiniResponse shopInfo(@RequestBody StaticParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(param.getStaffId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "参数：厂家标识为空!");
        }
        MyShop shop = this.myShopService.selectShopByStaffId(param.getStaffId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "厂家信息异常");
        }
        if (shop.getStatus().equals(0)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "厂家已被禁");
        }
        MyShopMemberQueryParam shopMemberQueryParam = new MyShopMemberQueryParam();
        shopMemberQueryParam.setShopid(shop.getId());
        shopMemberQueryParam.setStatus(0);
        Long auditnum = myShopMemberService.selectCount(shopMemberQueryParam);
        MyShopDto shopDto = new MyShopDto();
        BeanUtils.copyProperties(shop, shopDto);
        shopDto.setAuditnum(auditnum);
        shopDto.setShopurl(staticFiledConfig.getShopUrl());
        shopDto.setContent(StringEscapeUtils.unescapeHtml4(shop.getContent()));
        shopDto.setShebei(StringEscapeUtils.unescapeHtml4(shop.getShebei()));
        return WxMiniResponse.ok(shopDto);
    }

    /**
     * regshop_[三期]厂家入驻
     *
     * @param param 通用参数查询类【StaticParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/regshop")
    public WxMiniResponse regshop(@RequestBody MyFactorySaveParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }

        if (ObjectUtils.isEmpty(param)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：参数为空");
        }
        if (ObjectUtils.isEmpty(param.getTitle())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请输入公司名称");
        }
        if (ObjectUtils.isEmpty(param.getTitle1())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请输入公司简称");
        }
        if (param.getTitle1().length() > 4 || param.getTitle1().length() < 2) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "公司简称应在1~4个字之间");
        }
        if (ObjectUtils.isEmpty(param.getLogo())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请上传logo");
        }
        if (ObjectUtils.isEmpty(param.getLat()) || ObjectUtils.isEmpty(param.getLng())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请选择地理位置");
        }
        if (ObjectUtils.isEmpty(param.getAddress())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请输入公司地址");
        }
        if (ObjectUtils.isEmpty(param.getContact())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请输入联系人姓名");
        }
        if (ObjectUtils.isEmpty(param.getPid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请选择生产类别");
        }
        if (ObjectUtils.isEmpty(param.getTelephone())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：请输入手机号码");
        }
        if (param.getTitle().matches("[AaBbCc].*")) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：公司名称不能以ABC开头");
        }
        if (ObjectUtils.isEmpty(param.getId()) && this.myShopService.isValidName(param.getTitle())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败：厂家名称已经存在，请重新输入");
        }
        MyShop shop = new MyShop();
        BeanUtils.copyProperties(param, shop);
        if (!ObjectUtils.isEmpty(shop.getLat()) && !ObjectUtils.isEmpty(shop.getLng())) {
            ToolsLocation toolsLocation = ToolsUtils.qq2baidu(shop.getLat(), shop.getLng());
            shop.setLat(toolsLocation.getLat());
            shop.setLng(toolsLocation.getLng());
            shop.setLatgd(shop.getLat());
            shop.setLnggd(shop.getLng());
            BaiduReverseGeocoding baiduReverseGeocoding = BaiduMapUtils.getBaiduAddressInfo(shop.getLng(), shop.getLat());
            if (!ObjectUtils.isEmpty(baiduReverseGeocoding)) {
                BaiduAddressComponent addressComponent = baiduReverseGeocoding.getResult().getAddressComponent();
                if (!ObjectUtils.isEmpty(addressComponent)) {
                    String region = addressComponent.getProvince() + "," + addressComponent.getCity() + "," + addressComponent.getDistrict();
                    shop.setRegion(region);
                    shop.setPcd(region);
                    String code = addressComponent.getAdcode();
                    if (!ObjectUtils.isEmpty(code)) {
                        shop.setDistrictid(code);
                        shop.setDistrictid1(code.substring(0, 4));
                        shop.setDistrictid2(code.substring(0, 2));
                    }
                }
            }
        }
        shop.setEn(ToolsUtils.getFirstLetterUpper(shop.getTitle()));
        shop.setPid("," + shop.getPid() + ",");
        if (!ObjectUtils.isEmpty(shop.getId()) && shop.getId() > 0) {
            // 打回重新更新操作；
            MyShop editShop = this.myShopService.selectShopByStaffId(currentStaff.getId());
            if (ObjectUtils.isEmpty(shop)) {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "更新数据时校验失败：您的厂家异常");
            }
            BeanUtils.copyProperties(shop, editShop);
            editShop.setAudit(0);
            editShop = myShopService.updateEntity(editShop);
            if (ObjectUtils.isEmpty(editShop)) {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "更新数据失败");
            }
        } else {
            shop.setId(null);
            // 新厂家入驻，新增操作；
            MyShop addShop = this.myShopService.selectShopByStaffId(currentStaff.getId());
            if (!ObjectUtils.isEmpty(addShop)) {
                if (addShop.getAudit().equals(1)) {
                    return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "重复入驻的工厂信息【名称：" + addShop.getTitle() + "，电话：" + addShop.getTelephone() + "】");
                }
            }
            String userpwd = ToolsUtils.bin2hexFast(ToolsUtils.randomBytes(5));
            shop.setUserpwd(MD5EncryptionUtils.md5(userpwd));
            shop.setStaffid(currentStaff.getId());
            shop.setAudit(0);
            shop.setPs(userpwd);
            shop.setBgcolor("#ffffff");
            if (!ObjectUtils.isEmpty(currentStaff.getInvitecode())) {
                if (!ObjectUtils.isEmpty(currentStaff.getOutinvitetime())) {
                    Long time = new Date().getTime() / 1000;
                    if (currentStaff.getOutinvitetime() > time) {
                        shop.setInvitecode(Integer.parseInt(currentStaff.getInvitecode()));
                    } else {
                        shop.setInvitecode(1);
                    }
                }
            }
            shop.setAddtime(new Date());
            shop.setUsername(shop.getTelephone());
            shop.setEn(ToolsUtils.getFirstLetterUpper(shop.getTitle()));
            shop = this.myShopService.addEntity(shop);
            if (ObjectUtils.isEmpty(shop)) {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "入驻失败");
            }
        }
        return WxMiniResponse.ok(shop);
    }

    /**
     * setshopinfo [二期]厂家设置税率备注等
     *
     * @param param 厂家设置税率备注查询类【ShopInfoQueryParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/setshopinfo")
    public WxMiniResponse setshopinfo(@RequestBody MyShopInfoSaveParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }

        MyShop shop = myShopService.selectShopByStaffId(currentStaff.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您还没有成为厂家");
        }
        if (ObjectUtils.isEmpty(param.getTaxrate())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请设置税率");
        }
        try {
            double value = Double.parseDouble(param.getTaxrate() + "");
        } catch (NumberFormatException e) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请输入有效的税率值");
        }
        shop.setTaxrate(param.getTaxrate());
        shop.setBaojiaremark(param.getBaojiaremark());
        shop.setXiaoshouremark(param.getXiaoshouremark());
        shop = this.myShopService.updateEntity(shop);
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败");
        }
        return WxMiniResponse.ok("成功");
    }

    /**
     * setshophome [二期]厂家设置首页信息等
     *
     * @param param 厂家设置税率备注查询类【ShopInfoQueryParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/setshophome")
    public WxMiniResponse setshophome(@RequestBody MyShopInfoSaveParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }

        if (ObjectUtils.isEmpty(param.getContent()) || param.equals("")) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请设置公司介绍！");
        }

        MyShop shop = myShopService.selectShopByStaffId(currentStaff.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您还没有成为厂家");
        }

        String images = "";
        if (!ObjectUtils.isEmpty(param.getImages())) {
            images = JSONArray.toJSONString(param.getImages().split(","));
        }
        shop.setShowhomepage(param.getShowhomepage());
        shop.setContent(param.getContent());
        shop.setImages(images);
        shop.setShebei(param.getShebei());
        shop.setBgcolor(param.getBgcolor());
        shop = this.myShopService.updateEntity(shop);
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败");
        }
        return WxMiniResponse.ok();
    }

    /**
     * shopalbumcate [二期]获取厂家相册分类列表
     *
     * @param param 厂家设置税率备注查询类【ShopInfoQueryParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/shopalbumcate")
    public WxMiniResponse shopalbumcate(@RequestBody MyShopAlbumCateQueryParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        MyShop shop = myShopService.selectShopByStaffId(currentStaff.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您还没有成为厂家");
        }
        MyShopAlbumCateQueryParam queryParam = new MyShopAlbumCateQueryParam();
        queryParam.setShopid(shop.getId());
        List<MyShopAlbumCate> results = myShopAlbumCateService.selectList(queryParam);
        return WxMiniResponse.ok(results);
    }

    /**
     * addshopalbumcate [二期]新增厂家相册分类列表
     *
     * @param param 厂家设置税率备注查询类【ShopInfoQueryParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/addshopalbumcate")
    public WxMiniResponse addshopalbumcate(@RequestBody MyShopAlbumCateSaveParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        MyShop shop = myShopService.selectShopByStaffId(currentStaff.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您还没有成为厂家", "您还没有成为厂家！");
        }
        MyShopAlbumCate shopAlbumCate = new MyShopAlbumCate();
        BeanUtils.copyProperties(param, shopAlbumCate);
        shopAlbumCate.setShopid(shop.getId());
        if (!ObjectUtils.isEmpty(shopAlbumCate) && !ObjectUtils.isEmpty(shopAlbumCate.getId())) {
            shopAlbumCate = myShopAlbumCateService.updateEntity(shopAlbumCate);
        } else {
            Integer sort = myShopAlbumCateService.getMaxSort(shop.getId());
            shopAlbumCate.setSort(sort + 1);
            shopAlbumCate.setAddtime(new Date());
            shopAlbumCate = myShopAlbumCateService.addEntity(shopAlbumCate);
        }
        if (ObjectUtils.isEmpty(shopAlbumCate)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "添加失败！", "添加失败！");
        }
        return WxMiniResponse.ok(shopAlbumCate);
    }

    /**
     * deleteshopalbumcate [二期]删除厂家相册分类列表
     *
     * @param param 厂家设置税率备注查询类【ShopInfoQueryParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/deleteshopalbumcate")
    public WxMiniResponse deleteshopalbumcate(@RequestBody StaticParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        MyShop shop = myShopService.selectShopByStaffId(currentStaff.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您还没有成为厂家");
        }
        if (ObjectUtils.isEmpty(param.getId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请选择要删除的分类");
        }

        Boolean result = this.myShopAlbumCateService.deletetById(param.getId());
        if (result) {
            return WxMiniResponse.ok("操作成功");
        } else {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败");
        }
    }

    /**
     * sorteshopalbumcate [二期]排序厂家相册分类列表
     *
     * @param param 厂家设置税率备注查询类【ShopInfoQueryParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/sorteshopalbumcate")
    public WxMiniResponse sorteshopalbumcate(@RequestBody MyShopAlbumCateSaveParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        MyShop shop = myShopService.selectShopByStaffId(currentStaff.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您还没有成为厂家", "您还没有成为厂家！");
        }
        if (ObjectUtils.isEmpty(param.getSort())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请输入排序序号");
        }
        MyShopAlbumCate shopAlbumCate = new MyShopAlbumCate();
        shopAlbumCate.setId(param.getId());
        shopAlbumCate.setShopid(shop.getId());
        shopAlbumCate.setSort(param.getSort());
        shopAlbumCate = myShopAlbumCateService.updateEntity(shopAlbumCate);
        if (ObjectUtils.isEmpty(shopAlbumCate)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "修改失败！", "修改失败！");
        }
        return WxMiniResponse.ok(shopAlbumCate);
    }

    /**
     * shopalbumlist [二期]查询厂家产品相册列表
     *
     * @param param 厂家设置税率备注查询类【ShopInfoQueryParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/shopalbumlist")
    public WxMiniResponse shopalbumlist(@RequestBody MyShopAlbumListQueryParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        MyShop shop = myShopService.selectShopByStaffId(currentStaff.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您还没有成为厂家", "您还没有成为厂家！");
        }
        param.setShopid(shop.getId());
        WxMiniPageDto<MyShopAlbumList> list = this.myShopAlbumListService.selectPageList(param);
        return WxMiniResponse.ok(list);
    }

    /**
     * addshopalbum [二期]新增厂家产品相册列表
     *
     * @param param 厂家设置税率备注查询类【ShopInfoQueryParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/addshopalbum")
    public WxMiniResponse addshopalbum(@RequestBody MyShopAlbumListSaveParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        MyShop shop = myShopService.selectShopByStaffId(currentStaff.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您还没有成为厂家", "您还没有成为厂家！");
        }

        param.setShopid(shop.getId());
        MyShopAlbumList shopAlbumList = new MyShopAlbumList();
        BeanUtils.copyProperties(param, shopAlbumList);
        if (!ObjectUtils.isEmpty(param.getId()) && param.getId() > 0) {
            shopAlbumList = this.myShopAlbumListService.updateEntity(shopAlbumList);
        } else {
            shopAlbumList.setAddtime(new Date());
            shopAlbumList = this.myShopAlbumListService.addEntity(shopAlbumList);
        }
        if (!ObjectUtils.isEmpty(shopAlbumList)) {
            return WxMiniResponse.ok(shopAlbumList);
        } else {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败！");
        }
    }

    /**
     * shopalbumdelete [二期]删除厂家产品相册列表
     *
     * @param param 厂家设置税率备注查询类【ShopInfoQueryParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/shopalbumdelete")
    public WxMiniResponse shopalbumdelete(@RequestBody MyShopAlbumListDeleteParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        MyShop shop = myShopService.selectShopByStaffId(currentStaff.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您还没有成为厂家", "您还没有成为厂家！");
        }

        if (ObjectUtils.isEmpty(param.getId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请选择要删除的目录", "请选择要删除的目录！");
        }
        if (!ObjectUtils.isEmpty(param.getId())) {
            String[] idArray = param.getId().split(",");
            List<Integer> idList = new ArrayList<>();
            for (String item : idArray) {
                idList.add(Integer.parseInt(item));
            }
            Boolean result = this.myShopAlbumListService.deleteByIds(idList);
            if (result) {
                return WxMiniResponse.ok(result);
            }
        }
        return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败！");
    }

    /**
     * shopmemberlist [二期]获取厂家询价申请审核列表
     *
     * @param param 厂家设置税率备注查询类【ShopInfoQueryParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/shopmemberlist")
    public WxMiniResponse shopmemberlist(@RequestBody MyShopMemberQueryParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        MyShop shop = myShopService.selectShopByStaffId(currentStaff.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您还没有成为厂家", "您还没有成为厂家！");
        }
        param.setShopid(shop.getId());
        WxMiniPageDto<MyShopMember> list = this.myShopMemberService.selectPageList(param);
        return WxMiniResponse.ok(list);
    }

    /**
     * shopmemberaudit [二期]审核厂家询价申请
     *
     * @param param 厂家设置税率备注查询类【ShopInfoQueryParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/shopmemberaudit")
    public WxMiniResponse shopmemberaudit(@RequestBody MyShopMemberSaveParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        MyShop shop = myShopService.selectShopByStaffId(currentStaff.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您还没有成为厂家", "您还没有成为厂家！");
        }
        if (!ObjectUtils.isEmpty(param.getStatus()) && !param.getStatus().equals(1) && !param.getStatus().equals(2)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "状态不正确", "状态不正确！");
        }
        MyShopMember myShopMember = this.myShopMemberService.selectById(param.getId());
        if (ObjectUtils.isEmpty(myShopMember)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "会员查询失败", "会员查询失败！");
        }
        BeanUtils.copyProperties(param, myShopMember);
        myShopMember.setAudittime(new Date());
        if (param.getStatus().equals(2)) {
            myShopMember.setTip(1);
        }
        myShopMember = this.myShopMemberService.updateEntity(myShopMember);
        if (!ObjectUtils.isEmpty(myShopMember)) {
            return WxMiniResponse.ok(myShopMember);
        } else {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败！");
        }
    }

    /**
     * shopmemberdelete [二期]删除厂家询价申请
     *
     * @param param 厂家设置税率备注查询类【ShopInfoQueryParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/shopmemberdelete")
    public WxMiniResponse shopmemberdelete(@RequestBody BaseDeleteParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        MyShop shop = myShopService.selectShopByStaffId(currentStaff.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您还没有成为厂家", "您还没有成为厂家！");
        }
        if (ObjectUtils.isEmpty(param.getId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "参数标识为空", "参数标识为空！");
        }
        Boolean result = this.myShopMemberService.deleteEntity(param.getId());
        if (result) {
            return WxMiniResponse.ok(result);
        } else {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败", "操作失败！");
        }
    }

    /**
     * getprodparams1 [二期]查询产品规格名称型号等
     *
     * @param param 参数类【BaseDeleteParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/getprodparams1")
    public WxMiniResponse getprodparams1(@RequestBody MyCategoryProductQueryParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        MyShop shop = myShopService.selectShopByStaffId(currentStaff.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您还没有成为厂家", "您还没有成为厂家！");
        }
        param.setShopid(shop.getId());
        param.setPid(0);
        List<MyCategoryProduct> category1 = this.myCategoryProductService.selectList(param);
        List<MyCategoryProduct> category2 = new ArrayList<>();
        List<MyCategoryProduct> category3 = new ArrayList<>();
        List<MyCategoryProduct> category4 = new ArrayList<>();
        List<MyCategoryProduct> category5 = new ArrayList<>();
        Integer pid1 = null;
        Integer pid2 = null;
        Integer pid3 = null;
        Integer pid4 = null;
        Integer pid5 = null;
        if (!ObjectUtils.isEmpty(category1)) {
            param.setPid(category1.get(0).getId());
        }
        if (!ObjectUtils.isEmpty(param.getPid1())) {
            param.setPid(param.getPid1());
        }
        if (!param.getPid().equals(0)) {
            pid1 = param.getPid();
            category2 = this.myCategoryProductService.selectList(param);
            param.setPid(0);
        }
        if (!ObjectUtils.isEmpty(category2)) {
            param.setPid(category2.get(0).getId());
        }
        if (!ObjectUtils.isEmpty(param.getPid2())) {
            param.setPid(param.getPid2());
        }
        if (!param.getPid().equals(0)) {
            pid2 = param.getPid();
            category3 = this.myCategoryProductService.selectList(param);
            param.setPid(0);
        }
        if (!ObjectUtils.isEmpty(category3)) {
            param.setPid(category3.get(0).getId());
        }
        if (!ObjectUtils.isEmpty(param.getPid3())) {
            param.setPid(param.getPid3());
        }
        if (!param.getPid().equals(0)) {
            pid3 = param.getPid();
            category4 = this.myCategoryProductService.selectList(param);
            param.setPid(0);
        }
        if (!ObjectUtils.isEmpty(category4)) {
            param.setPid(category4.get(0).getId());
        }
        if (!ObjectUtils.isEmpty(param.getPid4())) {
            param.setPid(param.getPid4());
        }
        if (!param.getPid().equals(0)) {
            pid4 = param.getPid();
            category5 = this.myCategoryProductService.selectList(param);
            param.setPid(0);
        }
        if (!ObjectUtils.isEmpty(category5)) {
            pid5 = category5.get(0).getId();
        }

        List<MyCategoryUnit> units = myCategoryUnitService.selectList(new MyCategoryUnitQueryParam());
        List<MyCategoryProduct> changepricepid1list = this.myCategoryProductService.selectListToShopId(shop.getId());
        Map<String, Object> map = new HashMap<>();
        map.put("category1", category1);
        map.put("pid1", pid1);
        map.put("category2", category2);
        map.put("pid2", pid2);
        map.put("category3", category3);
        map.put("pid3", pid3);
        map.put("category4", category4);
        map.put("pid4", pid4);
        map.put("category5", category5);
        map.put("pid5", pid5);
        map.put("changepricepid1list", changepricepid1list);
        map.put("unit", units);
        map.put("tip", "pid1-名称，pid2-电压，pid3-型号，pid4-结构，pid5-规格");
        return WxMiniResponse.ok(map);

    }

    /**
     * getChangePrice [二期]获取已添加价格的产品；
     *
     * @param param 参数类【BaseDeleteParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/getChangePrice")
    public WxMiniResponse getChangePrice(@RequestBody StaticParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        MyShop shop = myShopService.selectShopByStaffId(currentStaff.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您还没有成为厂家", "您还没有成为厂家！");
        }
        List<MyCategoryProduct> list = this.myCategoryProductService.selectListToShopId(shop.getId());

        return WxMiniResponse.ok(list);
    }

    /**
     * getproduct [二期]获取产品；
     *
     * @param param 参数类【BaseDeleteParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/getproduct")
    public WxMiniResponse getproduct(@RequestBody MyFactoryProductQueryParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        MyShop shop = myShopService.selectShopByStaffId(currentStaff.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您还没有成为厂家", "您还没有成为厂家！");
        }
        if (ObjectUtils.isEmpty(param.getPid1())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请选择系列名称", "请选择系列名称！");
        }
        if (ObjectUtils.isEmpty(param.getPid2())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请选择型号", "请选择型号！");
        }
        if (ObjectUtils.isEmpty(param.getPid3())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请选择电压", "请选择电压！");
        }
        if (ObjectUtils.isEmpty(param.getPid4())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请选择结构", "请选择结构！");
        }
        if (ObjectUtils.isEmpty(param.getPid5())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请选择规格", "请选择规格！");
        }
        param.setShopid(shop.getId());
        MyFactoryProduct selectOne = myFactoryProductService.selectOne(param);
        Map<String, Object> map = new HashMap<>();
        map.put("product", null);
        if (!ObjectUtils.isEmpty(selectOne)) {
            MyFactoryProductDto result = new MyFactoryProductDto();
            if (!ObjectUtils.isEmpty(selectOne)) {
                BeanUtils.copyProperties(selectOne, result);
                result.setUnitPricename(myCategoryUnitService.getCategoryUnitName(selectOne.getUnitPrice()));
                result.setUnitPriceQname(myCategoryUnitService.getCategoryUnitName(selectOne.getUnitPriceQ()));
                result.setUnitPriceZname(myCategoryUnitService.getCategoryUnitName(selectOne.getUnitPriceZ()));
            }
            result.setIstax(shop.getIstax());
            result.setTaxrate(shop.getTaxrate());
            map.put("product", result);
        }
        return WxMiniResponse.ok(map);
    }

    /**
     * addproductcate [二期]添加产品名称、规格型号，电压等；
     *
     * @param param 参数类【BaseDeleteParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/addproductcate")
    public WxMiniResponse addproductcate(@RequestBody MyFactoryProductSaveParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        MyShop shop = myShopService.selectShopByStaffId(currentStaff.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您还没有成为厂家", "您还没有成为厂家！");
        }

        if (ObjectUtils.isEmpty(param.getField())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "参数为空", "参数为空！");
        }
        Integer pid = 0;
        String name = param.getName();
        switch (param.getField()) {
            case "pid1":
                pid = 0;
                break;
            case "pid2":
                if (ObjectUtils.isEmpty(param.getPid1())) {
                    return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请选择产品名称", "请选择产品名称！");
                }
                pid = param.getPid1();
                break;
            case "pid3":
                if (ObjectUtils.isEmpty(param.getPid2())) {
                    return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请选择电压/特性", "请选择电压/特性！");
                }
                pid = param.getPid2();
                break;
            case "pid4":
                if (ObjectUtils.isEmpty(param.getPid3())) {
                    return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请选择型号", "请选择型号！");
                }
                pid = param.getPid3();
                break;
            case "pid5":
                if (ObjectUtils.isEmpty(param.getPid4())) {
                    return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请选择结构", "请选择结构！");
                }
                name = ToolsUtils.replaceCharToSearch1(param.getName());
                pid = param.getPid4();
                break;
        }

        MyCategoryProduct entity = new MyCategoryProduct();
        entity.setShopid(shop.getId());
        entity.setName(name);
        entity.setAddtime(new Date());
        entity.setPid(pid);
        entity.setStatus(1);
        entity = this.myCategoryProductService.addEntity(entity);
        if (ObjectUtils.isEmpty(entity)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "添加失败", "添加失败！");
        }
        return WxMiniResponse.ok(entity);
    }

    /**
     * deleteproductcate [二期]刪除产品名称、规格型号，电压等；
     *
     * @param param 参数类【BaseDeleteParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/deleteproductcate")
    public WxMiniResponse deleteproductcate(@RequestBody BaseDeleteParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }

        if (ObjectUtils.isEmpty(param.getId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "参数为空", "参数为空！");
        }

        MyShop shop = myShopService.selectShopByStaffId(currentStaff.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您还没有成为厂家", "您还没有成为厂家！");
        }

        MyCategoryProduct myCategoryProduct = this.myCategoryProductService.selectById(param.getId());
        if (ObjectUtils.isEmpty(myCategoryProduct)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您删除的数据不存在", "您删除的数据不存在！");
        }
        if (!myCategoryProduct.getShopid().equals(shop.getId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "不能删除别人添加的分类", "不能删除别人添加的分类！");
        }

        Boolean result = this.myCategoryProductService.deleteToAll(myCategoryProduct);
        if (!result) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "删除失败", "删除失败！");
        } else {
            return WxMiniResponse.ok("删除成功");
        }

    }

    /**
     * addproduct [二期]新增产品；
     *
     * @param param 参数类【BaseDeleteParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/addproduct")
    public WxMiniResponse addproduct(@RequestBody MyFactoryProductQueryParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }

//        if (ObjectUtils.isEmpty(param.getId())) {
////            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "参数为空", "参数为空！");
//        }

        MyShop shop = myShopService.selectShopByStaffId(currentStaff.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您还没有成为厂家", "您还没有成为厂家！");
        }

        if (ObjectUtils.isEmpty(param.getPid1())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请选择系列名称", "请选择系列名称！");
        }
        if (ObjectUtils.isEmpty(param.getPid2())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请选择型号", "请选择型号！");
        }
        if (ObjectUtils.isEmpty(param.getPid3())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请选择电压", "请选择电压！");
        }
        if (ObjectUtils.isEmpty(param.getPid4())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请选择结构", "请选择结构！");
        }
        if (ObjectUtils.isEmpty(param.getPid5())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请选择规格", "请选择规格！");
        }
        System.out.println(param);
        param.setShopid(shop.getId());
        ;
        MyFactoryProduct selectOne = myFactoryProductService.selectOne(param);
        if (!ObjectUtils.isEmpty(selectOne)) {
            selectOne.setIstax(shop.getIstax());
            selectOne.setTaxrate(shop.getTaxrate());
            selectOne.setPrice(param.getPrice());
            selectOne.setPriceZ(param.getPriceZ());
            selectOne.setPriceQ(param.getPriceQ());
            selectOne.setUnitPrice(param.getUnitPrice());
            selectOne.setUnitPriceQ(param.getUnitPriceQ());
            selectOne.setUnitPriceZ(param.getUnitPriceZ());
            selectOne.setPriceName(param.getPriceName());
            this.myFactoryProductService.updateEntity(selectOne);
        } else {
            selectOne = new MyFactoryProduct();
            BeanUtils.copyProperties(param, selectOne);
            MyCategoryProduct cate1 = this.myCategoryProductService.selectById(param.getPid1());
            MyCategoryProduct cate2 = this.myCategoryProductService.selectById(param.getPid2());
            MyCategoryProduct cate3 = this.myCategoryProductService.selectById(param.getPid3());
            MyCategoryProduct cate4 = this.myCategoryProductService.selectById(param.getPid4());
            MyCategoryProduct cate5 = this.myCategoryProductService.selectById(param.getPid5());
            selectOne.setShopid(shop.getId());
            selectOne.setProductid(0);
            selectOne.setPid1name(cate1.getName());
            selectOne.setPid2name(cate2.getName());
            selectOne.setPid3name(cate3.getName());
            selectOne.setPid4name(cate4.getName());
            selectOne.setPid5name(cate5.getName());
            selectOne.setTitle(cate5.getName());
            selectOne.setUnit("米");
            if (ObjectUtils.isEmpty(param.getPrice())) {
                selectOne.setPrice(0.0);
                selectOne.setUnitPrice(null);
            } else {
                selectOne.setPrice(param.getPrice());
                selectOne.setUnitPrice(param.getUnitPrice());
            }
            if (ObjectUtils.isEmpty(param.getPriceZ())) {
                selectOne.setPriceZ(0.0);
                selectOne.setUnitPriceZ(null);
            } else {
                selectOne.setPriceZ(param.getPriceZ());
                selectOne.setUnitPriceZ(param.getUnitPriceZ());
            }
            if (ObjectUtils.isEmpty(param.getPriceQ())) {
                selectOne.setPriceQ(0.0);
                selectOne.setUnitPriceQ(null);
            } else {
                selectOne.setPriceQ(param.getPriceQ());
                selectOne.setUnitPriceQ(param.getUnitPriceQ());
            }
            if (ObjectUtils.isEmpty(param.getPrice1())) {
                selectOne.setPrice1(0.0);
            }

            selectOne.setAddtime(new Date());
            selectOne.setStatus(1);
            selectOne.setTaxrate(shop.getTaxrate());
            selectOne.setPriceName(param.getPriceName());
            this.myFactoryProductService.addEntity(selectOne);
        }
        return WxMiniResponse.ok();
    }

    /**
     * deleteEntity [二期]删除产品；
     *
     * @param param 参数类【BaseDeleteParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/deleteEntity")
    public WxMiniResponse deleteEntity(@RequestBody BaseDeleteParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }

        if (ObjectUtils.isEmpty(param.getId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "参数为空", "参数为空！");
        }

        MyShop shop = myShopService.selectShopByStaffId(currentStaff.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您还没有成为厂家", "您还没有成为厂家！");
        }
        Boolean result = this.myFactoryProductService.deleteById(param.getId());
        if (result)
            return WxMiniResponse.ok();
        else
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "删除失败", "删除失败！");
    }

    /**
     * shophonorcate [二期]厂家荣誉分类
     *
     * @param param 参数类【BaseDeleteParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/shophonorcate")
    public WxMiniResponse shophonorcate(@RequestBody StaticParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        MyShop shop = myShopService.selectShopByStaffId(currentStaff.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您还没有成为厂家", "您还没有成为厂家！");
        }
        MyShopHonorCate honorCate = new MyShopHonorCate();
        honorCate.setShopid(shop.getId());
        List<MyShopHonorCate> list = this.myShopHonorCateService.selectList(honorCate);
        return WxMiniResponse.ok(list);
    }

    /**
     * addshophonorcate [二期]厂家荣誉分类-添加
     *
     * @param param 参数类【BaseDeleteParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/addshophonorcate")
    public WxMiniResponse addshophonorcate(@RequestBody MyShopHonorCate param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        MyShop shop = myShopService.selectShopByStaffId(currentStaff.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您还没有成为厂家", "您还没有成为厂家！");
        }
        if (!ObjectUtils.isEmpty(param.getId()) && param.getId() > 0) {
            this.myShopHonorCateService.updateEntity(param);
        } else {
            param.setShopid(shop.getId());
            param.setAddtime(new Date());
            this.myShopHonorCateService.addEntity(param);
        }
        return WxMiniResponse.ok();
    }

    /**
     * shopdetail [二期] 厂家详情页面信息展示；
     *
     * @param param 参数类【BaseDeleteParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/shopdetail")
    public WxMiniResponse shopdetail(@RequestBody MyShopQueryParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            if (!ObjectUtils.isEmpty(param.getContact()) && param.getContact().equals(1)) {
                //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
                return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
            }
        }

        if (ObjectUtils.isEmpty(param.getShopid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "厂家标识为空!", "厂家标识为空！");
        }
        MyShop shop = myShopService.selectShopByById(param.getShopid());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "厂家信息为空", "厂家信息为空！");
        }
        MyShopDto shopDto = new MyShopDto();
        BeanUtils.copyProperties(shop, shopDto);
        shopDto.setTelephone(Arrays.asList(shop.getTelephone().split(",")));
        shopDto.setBaojiaremark(StringEscapeUtils.unescapeHtml4(shop.getBaojiaremark()));
        shopDto.setXiaoshouremark(StringEscapeUtils.unescapeHtml4(shop.getXiaoshouremark()));
        shopDto.setContent(StringEscapeUtils.unescapeHtml4(shop.getContent()));
        shopDto.setShebei(StringEscapeUtils.unescapeHtml4(shop.getShebei()));
        if (!ObjectUtils.isEmpty(shop.getImages())) {
            String imagesString = JSONArray.parseArray(shop.getImages()).toJSONString();
            shopDto.setImages(Arrays.asList(imagesString.substring(1, imagesString.length() - 1).replace("\"", "").split(",")));
//            shopDto.setImages(Arrays.asList(shop.getImages().substring(1, shop.getImages().length() - 1).replace("\"", "").split(",")));
        }
        int isfav = 0;
        if (!ObjectUtils.isEmpty(currentStaff) && !ObjectUtils.isEmpty(currentStaff.getId())) {
            // 自己是否已关注
            MyFactoryFavQueryParam myFactoryFavQueryParam = new MyFactoryFavQueryParam();
            myFactoryFavQueryParam.setFavStaffid(shop.getStaffid());
            myFactoryFavQueryParam.setStaffId(currentStaff.getId());
            Long favCount = this.myFactoryFavService.selectCount(myFactoryFavQueryParam);
            if (ObjectUtils.isEmpty(favCount) || favCount == 0L) {
                isfav = 0;
            } else {
                isfav = 1;
            }
        }
        MyShopAlbumCateQueryParam queryParamCate = new MyShopAlbumCateQueryParam();
        queryParamCate.setShopid(shop.getId());
        List<MyShopAlbumCate> cateList = myShopAlbumCateService.selectList(queryParamCate);
        MyShopHonorCate myShopHonorCate = new MyShopHonorCate();
        myShopHonorCate.setShopid(shop.getId());
        List<MyShopHonorCate> honorList = myShopHonorCateService.selectList(myShopHonorCate);

        MyShopMemberQueryParam memberParam = new MyShopMemberQueryParam();
        memberParam.setShopid(shop.getId());
        memberParam.setStaffid(ObjectUtils.isEmpty(currentStaff) ? null : currentStaff.getId());
        List<MyShopMember> memberList = myShopMemberService.selectList(memberParam);
        MyShopMember myShopMember = null;
        Integer showprice = 0;
        if (!ObjectUtils.isEmpty(memberList) && memberList.size() > 0) {
            myShopMember = memberList.get(0);
        }
        if (!ObjectUtils.isEmpty(myShopMember)) {
            if (!ObjectUtils.isEmpty(myShopMember.getStatus()) && !myShopMember.getStatus().equals(1)) {
            } else {
                showprice = 1;
            }
        }
        Integer owner = 0;
        if (!ObjectUtils.isEmpty(currentStaff)) {
            if (currentStaff.getId().equals(shop.getStaffid())) {
                showprice = 1;
                owner = 1;
            }
        }
        if (shop.getPricestatus().equals(1))
            showprice = 1;

        Map<String, Object> map = new HashMap<>();
        map.put("owner", owner);
        map.put("isreg", 0);
        if (owner.equals(1)) {
            map.put("isreg", 1);
        } else {
            if (!ObjectUtils.isEmpty(myShopMember)) {
                map.put("isreg", 1);
            }
        }
        map.put("shopmember", myShopMember);
        map.put("showprice", showprice);
        map.put("shop", shopDto);
        map.put("shopmember", myShopMember);
        map.put("albumcate", cateList);
        map.put("honorcate", honorList);
        map.put("isfav", isfav);
        return WxMiniResponse.ok(map);
    }

    /**
     * shophonor [二期]厂家详情页-资质证书(厂家)
     *
     * @param param 参数类【BaseDeleteParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/shophonor")
    public WxMiniResponse shophonor(@RequestBody MyShopHonorQueryParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
//            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(param.getShopid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "参数id无效", "参数id无效！");
        }
        MyShop shop = myShopService.selectShopByById(Integer.parseInt(param.getShopid()));
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "无法查找到该厂家", "无法查找到该厂家！");
        }
        WxMiniPageDto<MyShopHonor> list = myShopHonorService.selectPageList(param);

        return WxMiniResponse.ok(list);
    }

    /**
     * shopalbum [二期]厂家详情页-相册(厂家)
     *
     * @param param 参数类【BaseDeleteParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/shopalbum")
    public WxMiniResponse shopalbum(@RequestBody MyShopAlbumList1QueryParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
//            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(param.getShopid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "参数id无效", "参数id无效！");
        }
        MyShopAlbumListQueryParam queryParam = new MyShopAlbumListQueryParam();
        BeanUtils.copyProperties(param, queryParam);
        queryParam.setShopid(Integer.parseInt(param.getShopid()));
        MyShop shop = myShopService.selectShopByById(queryParam.getShopid());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "无法查找到该厂家", "无法查找到该厂家！");
        }
        WxMiniPageDto<MyShopAlbumList> list = myShopAlbumListService.selectPageList(queryParam);
        return WxMiniResponse.ok(list);
    }


    /**
     * getprodparams [二期]查询产品规格名称型号等
     *
     * @param param 参数类【BaseDeleteParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/getOurProdparams")
    public WxMiniResponse getOurProdparams(@RequestBody MyOurCategoryProductQueryParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
//            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(param.getShopid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "参数id无效", "参数id无效！");
        }

        MyCategoryProductQueryParam queryParam0 = new MyCategoryProductQueryParam();
        queryParam0.setShopid(Integer.parseInt(param.getShopid()));
        queryParam0.setPid1(null);
        List<MyCategoryProduct> category1 = this.myCategoryProductService.selectOurFactoryProductList(queryParam0);
        List<MyCategoryProduct> category2 = new ArrayList<>();
        List<MyCategoryProduct> category3 = new ArrayList<>();
        List<MyCategoryProduct> category4 = new ArrayList<>();
        List<MyCategoryProduct> category5 = new ArrayList<>();

        MyCategoryProductQueryParam queryParam1 = new MyCategoryProductQueryParam();
        queryParam1.setShopid(Integer.parseInt(param.getShopid()));
        if (!ObjectUtils.isEmpty(param.getPid1())) {
            queryParam1.setPid1(param.getPid1());
        } else if (!ObjectUtils.isEmpty(category1)) {
            queryParam1.setPid1(category1.get(0).getId());
        }
        if (!ObjectUtils.isEmpty(queryParam1.getPid1())) {
            category2 = this.myCategoryProductService.selectOurFactoryProductList(queryParam1);
        }
        MyCategoryProductQueryParam queryParam2 = new MyCategoryProductQueryParam();
        queryParam2.setShopid(Integer.parseInt(param.getShopid()));
        queryParam2.setPid1(null);
        if (!ObjectUtils.isEmpty(param.getPid2())) {
            queryParam2.setPid2(param.getPid2());
        } else if (!ObjectUtils.isEmpty(category2)) {
            queryParam2.setPid2(category2.get(0).getId());
        }
        if (!ObjectUtils.isEmpty(queryParam2.getPid2())) {
            category3 = this.myCategoryProductService.selectOurFactoryProductList(queryParam2);
        }

        MyCategoryProductQueryParam queryParam3 = new MyCategoryProductQueryParam();
        queryParam3.setShopid(Integer.parseInt(param.getShopid()));
        queryParam3.setPid1(null);
        queryParam3.setPid2(null);
        if (!ObjectUtils.isEmpty(param.getPid3())) {
            queryParam3.setPid3(param.getPid3());
        } else if (!ObjectUtils.isEmpty(category3)) {
            queryParam3.setPid3(category3.get(0).getId());
        }
        if (!ObjectUtils.isEmpty(queryParam3.getPid3())) {
            category4 = this.myCategoryProductService.selectOurFactoryProductList(queryParam3);
        }

        MyCategoryProductQueryParam queryParam4 = new MyCategoryProductQueryParam();
        queryParam4.setShopid(Integer.parseInt(param.getShopid()));
        queryParam4.setPid1(null);
        queryParam4.setPid2(null);
        queryParam4.setPid3(null);
        if (!ObjectUtils.isEmpty(param.getPid4())) {
            queryParam4.setPid4(param.getPid4());
        } else if (!ObjectUtils.isEmpty(category4)) {
            queryParam4.setPid4(category4.get(0).getId());
        }
        if (!ObjectUtils.isEmpty(queryParam4.getPid4())) {
            param.setPid4(queryParam4.getPid4());
            category5 = this.myCategoryProductService.selectOurFactoryProductList(queryParam4);
        }
        MyShop shop = myShopService.selectShopByById(Integer.parseInt(param.getShopid()));
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您还没有成为厂家", "您还没有成为厂家！");
        }
        MyShopDto shopDto = new MyShopDto();
        BeanUtils.copyProperties(shop, shopDto);


        Map<String, Object> map = new HashMap<>();
        map.put("category1", category1);
        map.put("pid1", ObjectUtils.isEmpty(category1) ? null : category1.get(0).getId());
        map.put("category2", category2);
        map.put("pid2", ObjectUtils.isEmpty(category2) ? null : category2.get(0).getId());
        map.put("category3", category3);
        map.put("pid3", ObjectUtils.isEmpty(category3) ? null : category3.get(0).getId());
        map.put("category4", category4);
        map.put("pid4", ObjectUtils.isEmpty(category4) ? null : category4.get(0).getId());
        map.put("category5", category5);
        map.put("pid5", ObjectUtils.isEmpty(category5) ? null : category5.get(0).getId());
        map.put("shop", shopDto);
        return WxMiniResponse.ok(map);
    }

    /**
     * getproductprice [二期]查询规格名称型号等对应的产品
     *
     * @param param 参数类【BaseDeleteParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/getproductprice")
    public WxMiniResponse getproductprice(@RequestBody MyFactoryProduct1QueryParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
//            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(param.getPid1())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请选择系列名称", "请选择系列名称！");
        }
        if (ObjectUtils.isEmpty(param.getPid2())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请选择型号", "请选择型号！");
        }
        if (ObjectUtils.isEmpty(param.getPid3())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请选择电压", "请选择电压！");
        }
        if (ObjectUtils.isEmpty(param.getPid4())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请选择结构", "请选择结构！");
        }
        if (ObjectUtils.isEmpty(param.getPid5())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请选择规格", "请选择规格！");
        }
        if (ObjectUtils.isEmpty(param.getShopid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "参数id无效", "参数id无效！");
        }
        MyShop shop = myShopService.selectShopByById(Integer.parseInt(param.getShopid()));
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "厂家信息查询失败", "厂家信息查询失败！");
        }

        MyFactoryProductQueryParam queryParam = new MyFactoryProductQueryParam();
        BeanUtils.copyProperties(param, queryParam);
        queryParam.setShopid(Integer.parseInt(param.getShopid()));
        MyFactoryProduct selectOne = myFactoryProductService.selectOne(queryParam);
        MyFactoryProductDto result = new MyFactoryProductDto();
        if (!ObjectUtils.isEmpty(selectOne)) {
            BeanUtils.copyProperties(selectOne, result);
            result.setUnitPricename(myCategoryUnitService.getCategoryUnitName(selectOne.getUnitPrice()));
            result.setUnitPriceQname(myCategoryUnitService.getCategoryUnitName(selectOne.getUnitPriceQ()));
            result.setUnitPriceZname(myCategoryUnitService.getCategoryUnitName(selectOne.getUnitPriceZ()));
        }
        result.setIstax(shop.getIstax());
        result.setTaxrate(shop.getTaxrate());
        Map<String, Object> map = new HashMap<>();
        map.put("product", result);
        return WxMiniResponse.ok(map);

    }

    /**
     * addcart [二期]报价单-加入(厂家)
     *
     * @param param 参数类【BaseDeleteParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/addcart")
    public WxMiniResponse addcart(@RequestBody ShopCartQueryParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(param.getId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少标识", "缺少标识！");
        }
        Map<String, Object> map = new HashMap<>();
        String title = "国标";
        MyFactoryProduct prod = this.myFactoryProductService.selectById(param.getId());
        if (ObjectUtils.isEmpty(prod)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "产品查询失败", "产品查询失败！");
        }
        if (!ObjectUtils.isEmpty(param.getPricetype())) {
            if (param.getPricetype().equals(2)) {
                title = "企标";
                if (!ObjectUtils.isEmpty(prod.getPriceName()) && !ObjectUtils.isEmpty(prod.getPriceName()) && ObjectUtils.isEmpty(prod.getPriceName().split(","))) {
                    title = prod.getPriceName().split(",")[0];
                }
            } else if (param.getPricetype().equals(3)) {
                title = "中标";
                if (!ObjectUtils.isEmpty(prod.getPriceName()) && !ObjectUtils.isEmpty(prod.getPriceName()) && ObjectUtils.isEmpty(prod.getPriceName().split(","))) {
                    title = prod.getPriceName().split(",")[1];
                }
            }
        }
        List<MyCart> cartList = new ArrayList<>();
        if (!ObjectUtils.isEmpty(param.getShopid())) {
            ShopCartQueryParam queryParam = new ShopCartQueryParam();
            queryParam.setProductid(param.getId());
            queryParam.setShopid(param.getShopid());
            queryParam.setShopmemberid(param.getShopmemberid());
            queryParam.setPricetype(param.getPricetype());
            queryParam.setStaffId(currentStaff.getId());
            queryParam.setSource(param.getSource());
            cartList = this.myCartService.selectList(queryParam);
            param.setSource(2);
        } else {
            ShopCartQueryParam queryParam = new ShopCartQueryParam();
            queryParam.setProductid(param.getId());
            queryParam.setPricetype(param.getPricetype());
            queryParam.setStaffId(currentStaff.getId());
            queryParam.setSource(param.getSource());
            cartList = this.myCartService.selectList(queryParam);
            param.setSource(1);
        }
        if (!ObjectUtils.isEmpty(cartList) && cartList.size() > 0) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "该产品已加入报价单", "该产品已加入报价单！");
        }
        MyCart cart = new MyCart();
        cart.setStaffid(currentStaff.getId());
        cart.setShopmemberid(0);
        if (!ObjectUtils.isEmpty(param.getShopid())) {
            cart.setShopid(Integer.parseInt(param.getShopid()));
            cart.setShopmemberid(!ObjectUtils.isEmpty(param.getShopmemberid()) ? param.getShopmemberid() : 0);
        } else {
            cart.setShopid(prod.getShopid());
//            cart.setShopmemberid(prod.getsho);
        }
        cart.setUtype(1);
        cart.setPlatproductid(prod.getProductid());
        cart.setProductid(prod.getId());
        cart.setPid1(prod.getPid1());
        cart.setPid2(prod.getPid2());
        cart.setPid3(prod.getPid3());
        cart.setPid4(prod.getPid4());
        cart.setPid5(prod.getPid5());
        cart.setNum(1);
        cart.setTitle(title);
        cart.setPrice(prod.getPrice());
        cart.setPriceZ(prod.getPriceZ());
        cart.setPriceQ(prod.getPriceQ());
        cart.setPricetype(param.getPricetype());
        cart.setDiscounttype(1);
        cart.setMode(1);
        cart.setDiscountrate(0.0);
        cart.setAddtime(new Date());
        MyFactoryProductDto myFactoryProductDto = new MyFactoryProductDto();
        BeanUtils.copyProperties(prod, myFactoryProductDto);
        cart.setProdinfo(JSON.toJSONString(myFactoryProductDto));
        cart.setIstax(param.getIstax());
        cart.setSource(param.getSource());
        cart.setSourceType(1);
        cart = this.myCartService.addEntity(cart);
        return WxMiniResponse.ok();
    }

    /**
     * cart [二期]报价单列表(厂家)
     *
     * @param param 参数类【BaseDeleteParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/cart")
    public WxMiniResponse cart(@RequestBody ShopCartQueryParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        Map<String, Object> map = new HashMap<>();
        if (!this.isCheckLogin(param.getGuid())) {
            map.put("list", new ArrayList<>());
            map.put("total", 0);
            map.put("'allnum'", 0);
//            return WxMiniResponse.ok(map);
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        MyShop shop = myShopService.selectShopByById(Integer.parseInt(param.getShopid()));
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "厂家信息查询失败", "厂家信息查询失败！");
        }
        Integer shopmemberid = null;
        if (shop.getStaffid().equals(currentStaff.getId())) {
            shopmemberid = 0;
            param.setShopmemberid(shopmemberid);
        }
        param.setStaffId(currentStaff.getId());
        param.setShopid(shop.getId().toString());
        List<MyCart> cartList = myCartService.selectList(param);
        final Integer[] allnum = new Integer[1];
        allnum[0] = 0;
        final Double[] total = new Double[1];
        total[0] = 0.0;
        List<MyCartDto> cartDtoList = cartList.stream().map(po -> {
            MyCartDto dto = new MyCartDto();
            BeanUtils.copyProperties(po, dto);
            MyFactoryProduct prod = this.myFactoryProductService.selectById(po.getProductid());
            MyFactoryProductDto productDto = new MyFactoryProductDto();
            if (!ObjectUtils.isEmpty(prod)) {
                BeanUtils.copyProperties(prod, productDto);
                dto.setProdinfo(productDto);
            }
            String unitname = "";
            Double price = 0.0;
            if (!ObjectUtils.isEmpty(prod)) {
                switch (po.getPricetype()) {
                    case 1:
                        price = po.getPrice();
                        unitname = myCategoryUnitService.getCategoryUnitName(prod.getUnitPrice());
                        break;
                    case 2:
                        price = po.getPriceQ();
                        unitname = myCategoryUnitService.getCategoryUnitName(prod.getUnitPriceQ());
                        break;
                    case 3:
                        price = po.getPriceZ();
                        unitname = myCategoryUnitService.getCategoryUnitName(prod.getUnitPriceZ());
                }
            }
            Double discount = 0.0;
            if (ObjectUtils.isEmpty(po.getDiscountrate())) {
                po.setDiscountrate(0.0);
            }
            switch (po.getMode()) {
                case 1:
                    //比例
                    discount = price * po.getDiscountrate() / 100;
                    break;
                case 2:
                    //固定值
                    discount = po.getDiscountrate();
                    break;
            }
            switch (po.getDiscounttype()) {
                case 1:
                    price = ToolsUtils.to_price(price + discount);
                    break;
                case 2:
                    price = ToolsUtils.to_price(price - discount);
                    break;
            }

            double taxrate = ObjectUtils.isEmpty(shop.getTaxrate()) ? 0 : shop.getTaxrate();
            if (!ObjectUtils.isEmpty(param.getIstax()) && param.getIstax() > 0 && po.getHastax() < 1) {
                price = ToolsUtils.to_price((100 + taxrate) * price / 100);
            }

            Double amount = (double) Math.round(price * po.getNum() * 100) / 100.0;
//            dto.setPrice(price);
//            dto.setUnitname(unitname);
//            dto.setAmount(amount);
            total[0] += amount;
            allnum[0] += po.getNum();

            dto.setPrice(new BigDecimal(ToolsUtils.to_price(price)).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
            dto.setPriceZ(po.getPriceZ().toString());
            dto.setPriceQ(po.getPriceQ().toString());
            dto.setUnitname(unitname);
            dto.setAmount(amount);
            dto.setFactoryname(shop.getTitle1());
            dto.setDiscountrate(po.getDiscountrate() > 0 ? po.getDiscountrate() : null);
            return dto;
        }).collect(Collectors.toList());
        map.put("list", cartDtoList);
        map.put("total", ToolsUtils.to_price(total[0]));
        map.put("allnum", allnum[0]);
        return WxMiniResponse.ok(map);

    }

    /**
     * getprodparams [二期]查询产品规格名称型号等
     *
     * @param param 参数类【BaseDeleteParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/alternum")
    public WxMiniResponse alternum(@RequestBody BaseDeleteParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(param.getId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "参数id无效", "参数id无效！");
        }
        if (!ObjectUtils.isEmpty(param.getNum()) && param.getNum() < 1) {
            // 如果不是新增数量，就删除该条数据；
            Boolean result = this.myCartService.deletetById(param.getId());
            if (result)
                return WxMiniResponse.ok();
            else {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "删除失败", "删除失败！");
            }
        } else {
            MyCart cart = new MyCart();
            cart.setId(param.getId());
            cart.setNum(param.getNum());
            cart = this.myCartService.updateEntity(cart);
            if (!ObjectUtils.isEmpty(cart))
                return WxMiniResponse.ok();
            else {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败", "操作失败！");
            }
        }
    }

    /**
     * setshoppricestatus 厂家设置价格开关
     *
     * @param param 参数类【BaseDeleteParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/setshoppricestatus")
    public WxMiniResponse setshoppricestatus(@RequestBody StaticParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }

        if (ObjectUtils.isEmpty(param.getPricestatus())) {
            param.setPricestatus(0);
        }

        MyShop shop = myShopService.selectShopByStaffId(currentStaff.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您还没有成为厂家，或您的厂家信息异常", "您还没有成为厂家，或您的厂家信息异常！");
        }
        shop.setPricestatus(param.getPricestatus());
        shop = this.myShopService.updateEntity(shop);
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败", "操作失败");
        } else {
            return WxMiniResponse.ok("");
        }
    }

    /**
     * shopalterprice [二期]品牌货源入驻：一键改价（新增）
     *
     * @param param 参数类【BaseDeleteParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/shopalterprice")
    public WxMiniResponse shopalterprice(@RequestBody AlterPriceQueryParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        MyShop shop = myShopService.selectShopByStaffId(currentStaff.getId());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "您还没有成为厂家", "您还没有成为厂家！");
        }

        if (!ObjectUtils.isEmpty(param) && param.getDiscounttype().equals(1)) {
            param.setDiscountrate(1 + (param.getDiscountrate() / 100));
        } else {
            param.setDiscountrate(1 - (param.getDiscountrate() / 100));
        }
        MyFactoryProductQueryParam factoryProductQueryParam = new MyFactoryProductQueryParam();
        factoryProductQueryParam.setShopid(shop.getId());
        factoryProductQueryParam.setPid1(param.getPid1());
        List<MyFactoryProduct> products = this.myFactoryProductService.selectList(factoryProductQueryParam);

        Double iscountrate = param.getDiscountrate();
        List<MyFactoryProduct> saveList = products.stream().map(po -> {
            po.setPrice(ToolsUtils.to_price(po.getPrice() * iscountrate));
            po.setPriceQ(ToolsUtils.to_price(po.getPriceQ() * iscountrate));
            po.setPriceZ(ToolsUtils.to_price(po.getPriceZ() * iscountrate));
            if (ObjectUtils.isEmpty(po.getPrice())) {
                po.setPrice(0.0);
            }
            if (ObjectUtils.isEmpty(po.getPriceQ())) {
                po.setPriceQ(0.0);
            }
            if (ObjectUtils.isEmpty(po.getPriceZ())) {
                po.setPriceZ(0.0);
            }
            return po;
        }).collect(Collectors.toList());
        Boolean result = this.myFactoryProductService.updateList(saveList);
        if (result) {
            return WxMiniResponse.ok("操作成功");
        } else {
            return WxMiniResponse.ok("设置失败");
        }
    }

    /**
     * alterprice [二期]报价单-调价
     *
     * @param param 参数类【BaseDeleteParam】；
     * @return 标准响应体封装基础登录信息返回数据
     * @ApiNote 支持基础信息与扩展信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/alterprice")
    public WxMiniResponse alterprice(@RequestBody OtherAlterPriceQueryParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(param.getMode())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少调价模式", "缺少调价模式");
        }
//        if (ObjectUtils.isEmpty(param.getDiscountrate())) {
//            param.setDiscountrate(0.0);
//        }
        if (!ObjectUtils.isEmpty(param.getId()) && param.getId() > 0) {
            MyCart cart = this.myCartService.selectById(param.getId());
            if (ObjectUtils.isEmpty(cart)) {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败", "操作失败");
            }
            Double discount = 0.0;
            if (param.getMode().equals(2)) {
                if (ObjectUtils.isEmpty(param.getDiscountrate())) {
                    discount = param.getDiscountrate();
                }
                param.setDiscountrate(0.0);
                cart.setPrice(discount);
                cart.setSingle(1);
                cart.setHastax(param.getIstax());
            }
            cart.setDiscountrate(param.getDiscountrate());
            cart.setDiscounttype(param.getDiscounttype());
            cart.setMode(param.getMode());
            cart.setRemark(param.getRemark());
            cart.setTaxremark(param.getTaxremark());
            cart.setIstax(param.getIstax());
            cart = this.myCartService.updateEntity(cart);
            if (ObjectUtils.isEmpty(cart)) {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败", "操作失败");
            }
        } else {
            List<MyCart> selectList = new ArrayList<>();
            if (!ObjectUtils.isEmpty(param.getShopid())) {
                ShopCartQueryParam queryParam = new ShopCartQueryParam();
                queryParam.setShopid(param.getShopid());
                queryParam.setStaffId(currentStaff.getId());
                queryParam.setSource(2);
                selectList = this.myCartService.selectList(queryParam);
            } else {
                ShopCartQueryParam queryParam = new ShopCartQueryParam();
                queryParam.setStaffId(currentStaff.getId());
                queryParam.setSource(2);
                selectList = this.myCartService.selectList(queryParam);
            }
            List<MyCart> updateList = new ArrayList<>();
            for (MyCart cart : selectList) {
                cart.setDiscountrate(param.getDiscountrate());
                cart.setDiscounttype(param.getDiscounttype());
                cart.setMode(param.getMode());
                cart.setRemark(param.getRemark());
                cart.setTaxremark(param.getTaxremark());
                cart.setIstax(0);
                cart.setSingle(0);
                updateList.add(cart);
            }
            Boolean result = this.myCartService.updateEntitys(updateList);
            if (!result) {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败", "操作失败");
            }
        }
        MyCart cart = new MyCart();
        cart.setTaxremark(param.getTaxremark());
        if (ObjectUtils.isEmpty(param.getId()) || param.getId() <= 0) {
            cart.setRemark(param.getRemark());
        }
        if (!ObjectUtils.isEmpty(param.getShopid())) {
            ShopCartQueryParam queryParam = new ShopCartQueryParam();
            queryParam.setShopid(param.getShopid());
            queryParam.setSource(2);
            queryParam.setStaffId(currentStaff.getId());
            queryParam.setShopmemberid(param.getShopmemberid());
            Boolean result = this.myCartService.updateQueryParam(cart, queryParam);
        } else {
            ShopCartQueryParam queryParam = new ShopCartQueryParam();
//            queryParam.setShopid(param.getShopid());
            queryParam.setSource(1);
            queryParam.setStaffId(currentStaff.getId());
//            queryParam.setShopmemberid(param.getShopmemberid());
            Boolean result = this.myCartService.updateQueryParam(cart, queryParam);
        }
        return WxMiniResponse.ok("操作成功");
    }


    /**
     * @api {GET} /Shop/delproduct [二期]产品管理-删除产品
     * @apiVersion 1.0.0
     * @apiName delproduct
     * @apiGroup Shop
     * @apiParam {string}  guid 登录标识
     * @apiParam {string}  id 商品名称id
     */
    @PostMapping("/delproduct")
    public WxMiniResponse delproduct(@RequestBody StaticParam staticParam) {
        if (ObjectUtils.isEmpty(staticParam.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(staticParam.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        MyFactoryProduct myFactoryProduct = myFactoryProductService.selectById(staticParam.getId());
        if (myFactoryProduct == null) {
            return WxMiniResponse.error(2013, "id不对！");
        }
        Boolean result = myFactoryProductService.deleteById(staticParam.getId());
        if (result == false) {
            return WxMiniResponse.error(2013, "操作失败");
        }
        return WxMiniResponse.ok("操作成功");
    }

    /**
     * @api {GET} /Shop/createorder [二期]报价单-生成
     * @apiVersion 1.0.0
     * @apiName delproduct
     * @apiGroup Shop
     * @apiParam {string}  guid 登录标识
     * @apiParam {string}  id 商品名称id
     */
    @PostMapping("/createorder")
    public WxMiniResponse createorder(@RequestBody MyOrderSaveParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }

        // 前端已经取消首页加入报价单的功能，这里java端强制传入参数必须包含厂家标识；即只能查询在厂家报价页面报价的信息；
        if (ObjectUtils.isEmpty(param.getShopid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "厂家标识为空", "厂家标识为空！");
        }
        MyShop shop = this.myShopService.selectShopByById(param.getShopid());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "厂家查询失败", "厂家查询失败！");
        }
        ShopCartQueryParam cartQueryParam = new ShopCartQueryParam();
        cartQueryParam.setStaffId(currentStaff.getId());
        cartQueryParam.setShopid(param.getShopid() + "");
        cartQueryParam.setSource(2);
        cartQueryParam.setSourceType(1);
        if (shop.getStaffid().equals(currentStaff.getId())) {
            cartQueryParam.setShopmemberid(0);
        }
        List<MyCart> cartList = this.myCartService.selectList(cartQueryParam);
//        // 这里订单号采用序列id加其他编码
//        Calendar calendar = Calendar.getInstance();
//        int year = calendar.get(Calendar.YEAR);
//        int month = calendar.get(Calendar.MONTH) + 1;
//        int day = calendar.get(Calendar.DAY_OF_MONTH);
//        String date = String.format("%04d%02d%02d", year, month, day);

        String[] taxremark = new String[1];
        String details;
        List<String> names = new ArrayList<>();
        final Integer[] allnum = new Integer[1];
        allnum[0] = 0;
        final Double[] total = new Double[1];
        total[0] = 0.0;
        String orderNo = new Date().getYear() + "" + new Date().getTime();
        List<MyOrderDetail> orderDetailsList = cartList.stream().map(po -> {
            MyOrderDetail dto = new MyOrderDetail();
            BeanUtils.copyProperties(po, dto);
            MyFactoryProduct prod = this.myFactoryProductService.selectById(po.getProductid());
            MyFactoryProductDto productDto = new MyFactoryProductDto();
            if (!ObjectUtils.isEmpty(prod)) {
                names.add(prod.getTitle());
                BeanUtils.copyProperties(prod, productDto);
                dto.setProdinfo(JSON.toJSONString(productDto));
            }
            String unitname = "";
            Double price = 0.0;
            switch (po.getPricetype()) {
                case 1:
                    price = po.getPrice();
                    unitname = myCategoryUnitService.getCategoryUnitName(prod.getUnitPrice());
                    break;
                case 2:
                    price = po.getPriceQ();
                    unitname = myCategoryUnitService.getCategoryUnitName(prod.getUnitPriceQ());
                    break;
                case 3:
                    price = po.getPriceZ();
                    unitname = myCategoryUnitService.getCategoryUnitName(prod.getUnitPriceZ());
            }
            Double discount = 0.0;
            double s = po.getDiscountrate()==null?0:po.getDiscountrate();
            switch (po.getMode()) {
                case 1:

                    //比例
                    discount = price * s / 100;
                    break;
                case 2:
                    //固定值
                    discount = s;
                    break;
            }
            switch (po.getDiscounttype()) {
                case 1:
                    price = ToolsUtils.to_price(price + discount);
                    break;
                case 2:
                    price = ToolsUtils.to_price(price - discount);
                    break;
            }
            double taxrate = ObjectUtils.isEmpty(shop.getTaxrate()) ? 0 : shop.getTaxrate();
            if (!ObjectUtils.isEmpty(param.getIstax()) && param.getIstax() > 0 && po.getHastax() < 1) {
                price = ToolsUtils.to_price((100 + taxrate) * price / 100);
            }

            Double amount = (double) Math.round(price * po.getNum() * 100) / 100.0;
//            dto.setPrice(price);
//            dto.setUnitname(unitname);
//            dto.setAmount(amount);
            total[0] += amount;
            allnum[0] += po.getNum();

            dto.setId(null);
            // 这里生成订单号是用于java的自定义字符串+时间戳，保证不存在相同的编码；
            dto.setOrderno(orderNo);
            dto.setSubfix(1);

            dto.setPrice(Double.parseDouble(new BigDecimal(ToolsUtils.to_price(price)).setScale(2, BigDecimal.ROUND_HALF_UP).toString()));
            dto.setPriceZ(Double.parseDouble(po.getPriceZ().toString()));
            dto.setPriceQ(Double.parseDouble(po.getPriceQ().toString()));
            dto.setAmount(amount);
            dto.setDiscountrate(po.getDiscountrate() !=null ? po.getDiscountrate() : null);

            MyCategoryProduct cate1 = this.myCategoryProductService.selectById(po.getPid1());
            MyCategoryProduct cate2 = this.myCategoryProductService.selectById(po.getPid2());
            MyCategoryProduct cate3 = this.myCategoryProductService.selectById(po.getPid3());
            MyCategoryProduct cate4 = this.myCategoryProductService.selectById(po.getPid4());
            MyCategoryProduct cate5 = this.myCategoryProductService.selectById(po.getPid5());
            dto.setPid1name(!ObjectUtils.isEmpty(cate1) ? cate1.getName() : "");
            dto.setPid2name(!ObjectUtils.isEmpty(cate2) ? cate2.getName() : "");
            dto.setPid3name(!ObjectUtils.isEmpty(cate3) ? cate3.getName() : "");
            dto.setPid4name(!ObjectUtils.isEmpty(cate4) ? cate4.getName() : "");
            dto.setPid5name(!ObjectUtils.isEmpty(cate5) ? cate5.getName() : "");
            taxremark[0] = po.getTaxremark();
            return dto;
        }).collect(Collectors.toList());

        MyOrder order = new MyOrder();
        order.setType(param.getType());
        order.setOrderno(orderNo);
        order.setSubfix(1);
        order.setName(String.join(", ", names));
        order.setNum(allnum[0]);
        order.setAmount(total[0]);
        if (!ObjectUtils.isEmpty(param.getIstax())) {
            if (!ObjectUtils.isEmpty(param.getTaxremark())) {
                order.setTaxremark(param.getTaxremark());
            } else {
                order.setTaxremark("含13%增值税");
            }
        }
        order.setBaojiaremark(shop.getBaojiaremark());
        order.setXiaoshouremark(shop.getXiaoshouremark());
        order.setTaxrate(shop.getTaxrate());
        order.setSourceType(1);
        order.setAddtime(new Date());
        order.setStaffid(currentStaff.getId());
        order.setUtype(1);
        order.setShopid(param.getShopid());
        order.setIstax(param.getIstax());
        order.setIszhou(param.getIszhou());
        order.setBiaozhun(param.getBiaozhun());
        order.setUserreal(param.getUserreal());
        order.setTelephone(param.getTelephone());
        order.setShopmemberid(param.getShopmemberid());
        order = this.myOrderService.addEntity(order);
        if (!ObjectUtils.isEmpty(order)) {
            Boolean result = this.myOrderDetailService.saveEntitys(orderDetailsList);
            if (result) {
                return WxMiniResponse.ok(orderNo);
            }
        }
        return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败", "操作失败！");

    }


    /**
     * @api {GET} /Shop/clearcart [二期]报价单-清空(厂家)
     * @apiVersion 1.0.0
     * @apiName delproduct
     * @apiGroup Shop
     * @apiParam {string}  guid 登录标识
     * @apiParam {string}  id 商品名称id
     */
    @PostMapping("/clearcart")
    public WxMiniResponse clearcart(@RequestBody MyCartDeleteParam deleteParam) {
        if (ObjectUtils.isEmpty(deleteParam.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(deleteParam.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(deleteParam.getShopid())) {
            deleteParam.setSource(1);
        } else {
            deleteParam.setSource(2);
            MyShop shop = this.myShopService.selectShopByById(Integer.parseInt(deleteParam.getShopid()));
            if (!ObjectUtils.isEmpty(shop)) {
                if (!shop.getStaffid().equals(currentStaff.getId())) {
                    if (ObjectUtils.isEmpty(deleteParam.getShopid())) {
                        return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "未登录", "未登录！");
                    }
                } else {
                    deleteParam.setShopmemberid(0);
                }
            }
        }
        deleteParam.setStaffid(currentStaff.getId());
        Boolean result = this.myCartService.deleteParam(deleteParam);
        if (!result) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败", "操作失败！");
        }
        return WxMiniResponse.ok("操作成功");
    }


    /**
     * @api {GET} /Shop/shopmemberreg 厂家会员询价
     * @apiVersion 1.0.0
     * @apiName delproduct
     * @apiGroup Shop
     * @apiParam {string}  guid 登录标识
     * @apiParam {string}  id 商品名称id
     */
    @PostMapping("/shopmemberreg")
    public WxMiniResponse shopmemberreg(@RequestBody MyShopMemberSaveParam param) {
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        MyShop shop = this.myShopService.selectShopByById(param.getShopid());
        if (ObjectUtils.isEmpty(shop)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "厂家查询失败", "厂家查询失败！");
        }
        MyShopMemberQueryParam memberParam = new MyShopMemberQueryParam();
        memberParam.setShopid(shop.getId());
        memberParam.setStaffid(currentStaff.getId());
        List<MyShopMember> memberList = myShopMemberService.selectList(memberParam);
        MyShopMember myShopMember = null;
        if (!ObjectUtils.isEmpty(memberList) && memberList.size() > 0) {
            myShopMember = memberList.get(0);
        }
        if (!ObjectUtils.isEmpty(myShopMember)) {
            if (myShopMember.getStatus() < 2) {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "'已申请询价！'", "'已申请询价！'！");
            }
        }
        MyShopMember shopMember = new MyShopMember();
        BeanUtils.copyProperties(param, shopMember);
        shopMember.setStaffid(currentStaff.getId());
        shopMember.setShopid(shop.getId());
        shopMember.setUserreal(currentStaff.getUserreal());
        shopMember.setLogo(currentStaff.getHeadimgurl());
        shopMember.setTelephone(currentStaff.getTelephone());
        shopMember.setAddtime(new Date());
        shopMember.setStatus(0);
        shopMember.setTip(0);

        if (!ObjectUtils.isEmpty(shopMember.getId()) && shopMember.getId() > 0) {
            this.myShopMemberService.updateEntity(shopMember);
        } else {
            this.myShopMemberService.addEntity(shopMember);
        }
        return WxMiniResponse.ok("操作成功");
    }

    /**
     * @api {GET} /Shop/editmembertip 修改厂家询价提示
     * @apiVersion 1.0.0
     * @apiName editmembertip
     * @apiGroup Shop
     * @apiParam {string}  guid 登录标识
     * @apiParam {string}  id 询价id
     * @apiParam {string}  tip 询价提示 0不提示  1提示
     */
    @PostMapping("/editmembertip")
    public WxMiniResponse editmembertip(@RequestBody MyShopMemberSaveParam param){
        if (ObjectUtils.isEmpty(param.getGuid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "缺少code", "缺少code！");
        }
        if (!this.isCheckLogin(param.getGuid())) {
            //如果用户未登陆，提示用户未登，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }

        MyShopMember myShopMember = this.myShopMemberService.selectById(param.getId());
        if(!ObjectUtils.isEmpty(myShopMember)){
            myShopMember.setTip(param.getTip());
            myShopMember = this.myShopMemberService.updateEntity(myShopMember);
            if(!ObjectUtils.isEmpty(myShopMember)){
                return WxMiniResponse.ok("提交成功");
            }
        }
        return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败", "操作失败！");
    }

}
